package com.ebupt.migu.music.redis.controller;

import com.ebupt.migu.music.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author admin
 */
@RestController
@RequestMapping("/redis")
public class RedisController {


    @Autowired
    private RedisService redisService ;


    @RequestMapping(value = "/set")
    public void set(String key, String value){
        redisService.set(key, value);
    }

    @RequestMapping(value = "/setLoss")
    public void setLoss(String key, String value,Long expireTime){
        redisService.set(key, value, expireTime);
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public String get(String key){
        return redisService.get(key).toString();
    }

    @RequestMapping(value = "/getSet")
    @ResponseBody
    public String getSet(String key){
        return redisService.getSet(key).toArray()[0].toString();
    }

    @RequestMapping(value = "/type")
    public String type(String key){
        return redisService.type(key).toString();
    }

    @RequestMapping(value = "/setHash")
    public void setHash(@RequestBody Map<String,Object> map, String redisKey){
        redisService.setHashKey(map,redisKey);
    }

    @RequestMapping(value = "/getHash")
    @ResponseBody
    public Object getHash(String key,String redisKey){
        return redisService.getHashVal(key,redisKey).toString();
    }

}